package servlet;
/**
 * 功能：显示水娃控制程序

 */

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.User;
import service.UserService;

@WebServlet("/showUser")
public class ShowUserServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 创建水娃服务对象
        UserService userService = new UserService();
        // 获取全部水娃
        List<User> users = userService.findAllUsers();
        // 获取session对象
        HttpSession session = request.getSession();
        // 把水娃列表以属性的方式保存到session里
        session.setAttribute("users", users);
        // 重定向到显示水娃页面（showUser.jsp）
        response.sendRedirect(request.getContextPath() + "/web/backend/showUser.jsp");
     
        
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
